package com.airclick.merchant.service.impl;

import com.airclick.merchant.entity.Commercial;
import com.airclick.merchant.repository.CommercialRepository;
import com.airclick.merchant.service.CommercialService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Transactional(rollbackFor=Exception.class)
@Service
public class CommercialServiceImpl implements CommercialService {


    @Resource
    private CommercialRepository commercialRepository;

    @Override
    public int accountInformation(String logo, String contactAddress, String contactNumber, String electronicMail ,String id ,String merchantName) {
        return commercialRepository.accountInformation(logo,contactAddress,contactNumber,electronicMail,id,merchantName);
    }

    @Override
    public Commercial selevtInformation(String merchantId) {
        return commercialRepository.findAllById(merchantId);
    }

    @Override
    public Commercial saveCommercial(String merUser, String email) {
        Commercial commercial = new Commercial();
        commercial.setUserId(merUser);
        commercial.setElectronicMail(email);
        commercial.setCreator(merUser);
        return commercialRepository.save(commercial);
    }

    @Override
    public List<Commercial> selectMerchantName(String id) {
        return commercialRepository.findAllByUserId(id);
    }

    @Override
    public int update(String id, String walletId) {
        return commercialRepository.update(id,walletId);
    }
}
